package aad.storyboard.model;

import java.util.HashMap;

import aad.storyboard.controller.GUIComposer;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.util.Log;

public class ShakeAnimation extends Animation{

	private int currentCoordinateX;
	private int currentCoordinateY;
	private float xIntervalMovement;
	private float yIntervalMovement;

	/**
	 *  shakes by moving an object of intervalMovement at each step, this is calculated by the duration and the extent of the shaking
	 */
	public ShakeAnimation(int movements, int variance,int duration, int time) {
		super(duration,time);
		this.currentCoordinateX = 0;
		this.currentCoordinateY = 0;
		this.currentDuration = 0;
		xIntervalMovement = (float) variance/intervals;
		yIntervalMovement = (float) variance/intervals;
	}
	

	/**
	 *  calculates random coordinates whithin a certain extent, to which the object is moved each time, making sure it lands where it started from 
	 */
	@Override
	public void animate() {
		if(this.active){
			for(Image obj : this.images){
				int pseudoRandomX = (int) ((Math.random()*10) -5);
				int pseudoRandomY = (int) ((Math.random()*10) -5);
				if(pseudoRandomX > 0)
					xIntervalMovement = -xIntervalMovement;
				if(pseudoRandomY>0)
					yIntervalMovement = -yIntervalMovement;
				obj.setPosX(obj.getPreciseX() + xIntervalMovement);
				obj.setPosY(obj.getPreciseY() + yIntervalMovement);
				this.currentCoordinateX += xIntervalMovement;
				this.currentCoordinateY += yIntervalMovement;
				if((this.intervals - this.currentDuration) < 300){
					obj.setPosX(obj.getPreciseX() - currentCoordinateX);
					obj.setPosY(obj.getPreciseY() - currentCoordinateY);
				}
			}
		}
	}

	@Override
	public void undo() {
		for(Image obj : this.images){
			obj.setPosX(obj.getPreciseX() - currentCoordinateX);
			obj.setPosY(obj.getPreciseY() - currentCoordinateY);
		}
	}

	@Override
	public void adjustParameters() {
		
	}
	

}
